package com.weibo.sdk.android;

import com.weibo.android.sdk.util.Utility;

/**
 * 
 * @author luopeng (luopeng@staff.sina.com.cn)
 */
public class Weibo {
	public static String URL_OAUTH2_ACCESS_AUTHORIZE = "https://open.weibo.cn/oauth2/authorize";

	private static Weibo mWeiboInstance = null;

	public static String app_key = "1883446693";//第三方应用的appkey
	public static String redirecturl = "http://www.sina.com";// 重定向url

	public Oauth2AccessToken accessToken = null;//AccessToken实例

	public static final String KEY_TOKEN = "access_token";
	public static final String KEY_EXPIRES = "expires_in";
	public static final String KEY_REFRESHTOKEN = "refresh_token";
	public static boolean isWifi=false;//当前是否为wifi
	/**
	 * 
	 * @param appKey 第三方应用的appkey
	 * @param redirectUrl 第三方应用的回调页
	 * @return Weibo的实例
	 */
	public synchronized static Weibo getInstance() {
		if (mWeiboInstance == null) {
			mWeiboInstance = new Weibo();
		}
		return mWeiboInstance;
	}
	/**
	 * 设定第三方使用者的appkey和重定向url
	 * @param appKey 第三方应用的appkey
	 * @param redirectUrl 第三方应用的回调页
	 */
	public void setupConsumerConfig(String appKey,String redirectUrl) {
		app_key = appKey;
		redirecturl = redirectUrl;
	}
	
	public static String getApp_key() {
		return app_key;
	}
	
	public static void setApp_key(String app_key) {
		Weibo.app_key = app_key;
	}
	
	public static String getRedirecturl() {
		return redirecturl;
	}
	
	public static void setRedirecturl(String redirecturl) {
		Weibo.redirecturl = redirecturl;
	}
	
	public Oauth2AccessToken getAccessToken() {
		return accessToken;
	}
	
	public void setAccessToken(Oauth2AccessToken accessToken) {
		this.accessToken = accessToken;
	}
	
	public String getOAuthURL()
	{
		WeiboParameters parameters = new WeiboParameters();
		parameters.add("client_id", app_key);
		parameters.add("response_type", "token");
		parameters.add("redirect_uri", redirecturl);
		parameters.add("display", "mobile");
		parameters.add("scope", "follow_app_official_microblog;statuses_to_me_read");

		String url = URL_OAUTH2_ACCESS_AUTHORIZE + "?" + Utility.encodeUrl(parameters);
		
		return url;
	}

}
